/**
 * @author Eddie
 * @date 2024-02-05
 * 东软手环网关
 */

const router = require("koa-router")();

const braceletMiddleware = require("../middleware/neusoft_bracelet");

// 定义路由前缀，没有可不添加
router.prefix("/api/bracelet");

// 获取康复课程
router.get("/getAllDataByPaperNos", async (ctx, next) => {
  try {
    let params = {
      paperNoList : ["210282198601032317"]
    }
    let kfkcObj = await braceletMiddleware.getAllDataByPaperNos(params);
    ctx.body = {
      code: 1,
      msg: "读取成功",
      data: JSON.parse(kfkcObj),
    };
  } catch (error) {
    console.log("getKfkc", error);
    ctx.body = {
      code: -1,
      msg: "读取失败：" + error,
      data: {},
    };
  }
});

/**
 * 推送消息
 * @title 标题（最大 6 个字）
 * @content 消息体
 * @dcIds 手环 id，不传为群发
 */
router.post("/pushAcMessage", async (ctx, next) => {
  let data = ctx.request.body;
  if (data.title == "" || data.content == "") {
    ctx.body = {
      code: -1,
      msg: "缺少 title 或者 content",
      data: {},
    };
  } else {
    let obj = {
      title: data.title,
      content: data.content,
      dcIds: data.dcIds,
    };
    try {
      let kfkcObj = await braceletMiddleware.pushAcMessage(obj);
      ctx.body = {
        code: kfkcObj.code,
        msg: kfkcObj.msg,
        data: kfkcObj.data,
      };
    } catch (error) {
      console.log("getKfkc", error);
      ctx.body = {
        code: -1,
        msg: kfkcObj.msg,
        data: {},
      };
    }
  }
});

module.exports = router;
